<?php

/**
 * News form.
 *
 * @package    elearning
 * @subpackage form
 * @author     Your name here
 */
class NewsForm extends BaseNewsForm
{
  public function configure()
  {
		unset($this['created_at'], $this['updated_at'], $this['news_tags_list']);
		
		$lang_current = sfContext::getInstance()->getUser()->getCulture();
		$this->languages = array($lang_current => $lang_current);
		$langs = array_keys($this->languages);
		$this->embedI18n($langs);
		foreach($this->languages as $lang => $label)
		{
		  $this->widgetSchema[$lang]->setLabel($label);
		}
		
		$this->widgetSchema['is_public'] = new sfWidgetFormInputCheckbox(array("value_attribute_value" => 1),array('value' => 1));		
		
		//$this->getWidget('title')->setAttribute('style', 'width:546px');
		
		$this->widgetSchema['thumb'] = new sfWidgetFormInputFileEditable(array(
		   'label'     => 'Thumbnail',
		   'file_src'  => '/uploads/assets/news/'.$this->getPicPath().'/thumb_'.$this->getObject()->getThumb(),
		   'is_image'  => true,
		   'edit_mode' => !$this->isNew(),
		   'template'  => '<div><p>%file%</p><p>%input%</p><p>%delete% %delete_label%</p></div>',
		));
		
		$this->validatorSchema['thumb'] = new sfValidatorFile(array(
		   'required'   => !((bool)($this->getObject()->getThumb())),
		   'mime_types' => 'web_images',
		   'path' => sfConfig::get('sf_upload_dir').'/assets/news/'.$this->getPicPath(),
		   'validated_file_class' => 'sfResizedFile',
		   'max_size'   => 41943040,
		));
		
		$this->widgetSchema['tags'] = new sfWidgetFormInput(array(),array('value' => Tags::getListTagsByString($this->getObject()->getId())));
		$this->getWidget('tags')->setAttribute('style', 'width:300px');
		$this->validatorSchema['tags'] = new sfValidatorString(array('required' => false));
  }

  protected function getPicPath()
  {
	return utilities::getSpreadPathByDate($this->getObject()->getCreatedAt());
  }    	 
  
}
